<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\model\User;
use think\exception\ValidateException;
use think\response\Json;
use app\common\tool\Result;
use think\facade\View;
use think\Response;

class Register extends Base
{
    public function index()
    {
        View::assign('sys', \app\common\controller\Config::lists());
        return View::fetch();
    }


    public function save(): Json
    {
        $param = $this->request->post();
        try {
            $this->validate($param, 'Register');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
        return json(User::_save($param,''));
    }
    
    public function verify(): Response
    {
        $code = $this->request->get('code');
        $nickname = \app\common\model\User::where('code|mobile', $code)->value('tag');
        if ($nickname) {
            return Result::success('success', $nickname);
        } else {
            return Result::fail('系统标识不存在', '系统标识不存在');
        }
    }

}
